package com.cskaoyan.catmall.service.Impl;

import com.cskaoyan.catmall.dao.WxHomeIndexMapper;
import com.cskaoyan.catmall.model.vo.WxHomeIndexVo;
import com.cskaoyan.catmall.service.WxHomeIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022-01-10-14-38
 * author : LL
 * description:
 */
@Service
public class WxHomeIndexServiceImpl implements WxHomeIndexService {
    @Autowired
    WxHomeIndexMapper homeIndexMapper;

    @Override
    public WxHomeIndexVo getIndex() {
        WxHomeIndexVo homeIndexVo = new WxHomeIndexVo();
        homeIndexVo.setBanner(homeIndexMapper.getBanner());
        homeIndexVo.setChannel(homeIndexMapper.getChannel());
        homeIndexVo.setBrandList(homeIndexMapper.getBrand());
        homeIndexVo.setCouponList(homeIndexMapper.getCoupon());
//        homeIndexVo.setGrouponList(homeIndexMapper.getGroupon());
//        PageHelper.startPage(1,6);
        List<WxHomeIndexVo.FloorGoodsListDTO> floorGoods = homeIndexMapper.getFloorGoods();
        for (WxHomeIndexVo.FloorGoodsListDTO floorGood : floorGoods) {
            List<WxHomeIndexVo.FloorGoodsListDTO.GoodsListDTO> goodsList = floorGood.getGoodsList();
            if (goodsList.size() >= 6){
                floorGood.setGoodsList(goodsList.subList(0,6));
                continue;
            }
        }
        homeIndexVo.setFloorGoodsList(floorGoods);
        homeIndexVo.setTopicList(homeIndexMapper.getTopic());
        homeIndexVo.setHotGoodsList(homeIndexMapper.getHotGoods());
        homeIndexVo.setNewGoodsList(homeIndexMapper.getNewGoods());
        return homeIndexVo;
    }
}